import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Clase para controlar los records del jugador.
 * 
 * @author Asael Hernández García
 * @version (a version number or a date)
 */
public class UserRecords extends Actor
{
    /**
     * Act - do whatever the UserRecords wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    private UserInfo jugador;
    
    public UserRecords()
    {
        if(UserInfo.isStorageAvailable() && UserInfo.getMyInfo() != null)
            this.jugador = UserInfo.getMyInfo();
    }
    
    public void guardaRecords(int puntos)
    {
         if((UserInfo.isStorageAvailable()) && (this.jugador != null) && ((puntos > this.jugador.getScore()) || (this.jugador.getInt(0) == 0))){ 
            this.jugador.setScore(puntos);
            this.jugador.setInt(0,1); 
            this.jugador.store();
        }
        
        if((UserInfo.isStorageAvailable()) && (this.jugador != null) && (puntos > this.jugador.getScore())){
            this.jugador.setScore(puntos);
            this.jugador.setInt(0,1); 
            this.jugador.store();
        }
    }
}
